Silence ERROR log on override_properties recovery path#1
Closed
pszypowicz wants to merge 1 commit into
Closed
Conversation
override_properties is designed to recover gracefully when the characteristic's existing value falls outside a newly-restricted valid_values set (e.g. SecuritySystemCurrentState defaults to StayArmed=0, but a consumer configures the characteristic for an alarm panel that does not advertise ARM_HOME and so removes 0 from valid_values). The recovery is silent from the caller's perspective: ValueError is caught and self.value is reset via _get_default_value(). The validator it relied on, valid_value_or_raise, still calls logger.error() before raising, leaking an "is an invalid value" line into the application log even though the situation is expected and recovered. Downstream this manifests in Home Assistant as spurious pyhap.characteristic ERRORs at every HomeKit accessory build for alarm panels that restrict StayArmed (issue ikalchev#473 and home-assistant/core#130564, #156142). Replace the try/except-around-validator pattern in override_properties with an explicit silent membership check. valid_value_or_raise itself is unchanged so callers like set_value (where ERROR-level logging is appropriate) keep their behavior.
Owner
Author
|
Superseded by the upstream PR ikalchev#491. Closing this fork-internal checkpoint. |
Owner
Author
|
The fix is now proposed upstream as ikalchev#491 - please follow and review it there. This fork PR was only a self-review checkpoint, so it's closed in favor of the upstream one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Service.configure_charcallsCharacteristic.override_propertiesto install a restrictedvalid_valuesset, thenset_valueto seed an initial value.override_propertiesis designed to recover gracefully when the characteristic's existing_value(the format default, set in__init__) falls outside the newly-restrictedvalid_values- it catches theValueErrorand falls back via_get_default_value().The validator it uses,
valid_value_or_raise, callslogger.error()before raising. So even though the recovery path is the intended behavior, every consumer that restrictsvalid_valuesfor a characteristic whose format-default is excluded leaks a spurious ERROR log line.This is what users hit at every HomeKit accessory build for alarm panels that do not advertise
ARM_HOME: theSecuritySystemCurrentStateandSecuritySystemTargetStatedefaults toStayArmed=0, but the configuredvalid_valuesexcludes 0. The existing recovery still kicks in correctly (HA's HomeKit accessory works fine), but the log fills with red entries that look like real failures.Root cause
valid_value_or_raiseis appropriate when the caller wants the validation error surfaced (e.g.set_value), but insideoverride_propertiesthe exception is by design caught and ignored - so the ERROR log is misleading.Fix
Replace the try/except-around-validator pattern with an explicit silent membership check.
valid_value_or_raiseitself is left unchanged so other callers retain ERROR-level logging.Behavior matrix is unchanged:
to_valid_valuevalid_valuesVerification
pytest tests/passes 188/188 relevant tests (one unrelated pre-existing failure on Python 3.14 intest_accessory_driver.py::test_start_from_syncdue to upstream's use of removedasyncio.SafeChildWatcher).characteristic.pyagainst a live Home Assistant Core install with a HomeKit-bridged alarm panel. The twopyhap.characteristicERROR lines that appeared on every HA restart are gone; the HomeKit accessory continues to function (state changes propagate, target state changes from the Home app reach the panel).Related
PR scope note
Opening this against the fork's
devbranch first as a self-review checkpoint before considering an upstream PR.